import tkinter as tk

x = 0
y = 0
def foo1(event):
    global x
    global y
    print(f'键盘事件发生：{event.char},{event.keycode}')
    if event.keycode == 68:
        x += 10
    elif event.keycode == 65:
        x -= 10
    elif event.keycode == 87:
        y -= 10
    elif event.keycode == 83:
        y += 10
    label1.place(x=x,y=y)

root = tk.Tk()
root.title('键盘')

label1 = tk.Label(root,text='信息')
label1.place(x=0,y=0)

# 设定焦点，这个元素会响应键盘事件
label1.focus_set()

# <Key>触发键盘事件
label1.bind('<Key>',foo1)

root.mainloop()